home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / objects in c ƒ / OIC Sources / memory.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-01  |  816 b   |  63 lines  |  [TEXT/KAHL]

  1. /*
  2.  *            Copyright © John Wainwright 1988
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include "oic.h"
  7. #include "generics.h"
  8. #include "memoryMgr.h"
  9.  
  10. char *
  11. salloc(n)
  12.     int    n;
  13. {
  14.     register Handle p;
  15.  
  16.     p = NewHandle((long)n);
  17.     HLock(p);
  18.     if (MemErr == 0)
  19.         return *p;
  20.     gprintf(error, "Ran out of memory.\n");
  21. }
  22.  
  23. char *
  24. scalloc(n)
  25.     register int    n;
  26. {
  27.     register Handle p;
  28.     register char     *q;
  29.  
  30.     p = NewHandle((long)n);
  31.     if (MemErr == 0)
  32.     {
  33.         HLock(p);
  34.         for (q = *p; n--;)
  35.             *q++ = 0;
  36.         return *p;
  37.     }
  38.     gprintf(error, "Ran out of memory.\n");
  39. }
  40.  
  41. char *
  42. srealloc(p, n)
  43.     char    *p;
  44.     int        n;
  45. {
  46.     register long     i;
  47.     register char    *q, *qq;
  48.     register Handle    ph;
  49.     
  50.     q = qq = scalloc(n);
  51.     ph = RecoverHandle(p);
  52.     for (i = GetHandleSize(ph); i--; )
  53.         *qq++ = *p++;
  54.     DisposHandle(ph);
  55.     return    q;
  56. }
  57.  
  58. int
  59. free(p)
  60.     char *p;
  61. {
  62.     DisposHandle(RecoverHandle(p));
  63. }